public class Solution {
    public int rob(int[] num) {
        int len = num.length;

        int take;
        int maxProfit = 0;
        int nonTake = 0;

        for(int i = 0; i < len; ++i) {
            take = nonTake + num[i];
            nonTake = maxProfit;
            maxProfit = Math.max(take, nonTake);
        }
        return maxProfit;
    }
}